package com.netstar.util;

import java.util.HashMap;

import com.netstar.request.DataRequest;
import com.netstar.request.HttpRequest;

public class RequestUtils {

	public static interface RequestCB {
		void onFail();
	}

	public static interface RecordChannelCB extends RequestCB {
		void onSuccess();
	}

	public static void recordChannel(final HashMap<String, String> params,
			final RecordChannelCB cb) {
		new DataRequest() {

			@Override
			public String getPath() {
				return "main/flow-record.action";
			}

			@Override
			public String getMethod() {
				return HttpRequest.POST;
			}

			@Override
			public HashMap<String, String> getData() {
				return params;
			}

			@Override
			public void onFail(String msg) {
				cb.onFail();
			}

			@Override
			public void onSuccess(String data) {
				if (null != data && data.equalsIgnoreCase("ok")) {
					cb.onSuccess();
				} else {
					cb.onFail();
				}
			}
		}.makeRequest();
	}

	public static void recordSoftware(final HashMap<String, String> params,
			final RecordChannelCB cb) {
		new DataRequest() {

			@Override
			public String getPath() {
				return "main/software-flow.action";
			}

			@Override
			public String getMethod() {
				return HttpRequest.POST;
			}

			@Override
			public HashMap<String, String> getData() {
				return params;
			}

			@Override
			public void onFail(String msg) {
				cb.onFail();
			}

			@Override
			public void onSuccess(String data) {
				if (null != data && data.equalsIgnoreCase("ok")) {
					cb.onSuccess();
				} else {
					cb.onFail();
				}
			}
		}.makeRequest();
	}

	public static void recordDataAlarm(final HashMap<String, String> params) {
		new DataRequest() {

			@Override
			public String getPath() {
				return "main/set-dataalarm.action";
			}

			@Override
			public String getMethod() {
				return HttpRequest.POST;
			}

			@Override
			public HashMap<String, String> getData() {
				return params;
			}

			@Override
			public void onFail(String msg) {
			}

			@Override
			public void onSuccess(String data) {
			}
		}.makeRequest();
	}

}
